package com.media.publish.adapter;

import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;

import com.baidu.mapapi.search.core.PoiInfo;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.media.R;


public class LocationAdapter extends BaseQuickAdapter<PoiInfo, BaseViewHolder> {

    private String searchStr;


    public void setSearchStr(String searchStr) {
        this.searchStr = searchStr;
    }

    public LocationAdapter() {
        super(R.layout.item_text_layout);
    }

    @Override
    protected void convert(BaseViewHolder helper, PoiInfo item) {
        String content = item.getName();

        if (TextUtils.isEmpty(searchStr)) {
            helper.setText(R.id.tv_dynamicLocation_title, content);
        } else if (content.contains(searchStr)) {
            SpannableString spannableString = new SpannableString(content);
            spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#F54D53")), content.indexOf(searchStr), content.indexOf(searchStr) + searchStr.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            helper.setText(R.id.tv_dynamicLocation_title, spannableString);
        } else {
            helper.setText(R.id.tv_dynamicLocation_title, content);
        }

        String buffer = item.getAddress();
        helper.setText(R.id.tv_dynamicLocation_des, buffer);
    }
}